package top.boycharse.blog.common;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

public class WriterHelp {
    private WriterHelp() {}

    public static void write(HttpServletResponse response,Object object) {
        try(OutputStream outputStream = response.getOutputStream()) {
            // 返回json数据
            response.setContentType(Constants.CONTENT_TYPE);
            ObjectMapper mapper = new ObjectMapper();
            mapper.writeValue(outputStream,object);
        }catch (IOException e) {
            e.printStackTrace();
        }finally {

        }
    }
}
